package models

import (
	"gorm.io/gorm"
	"time"
	"user-srv/basic/inits"
)

// 会员权益表
type MemberBenefit struct {
	Id        uint64         `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	Name      string         `gorm:"column:name;type:varchar(255);comment:权益名称;not null;" json:"name"`                            // 权益名称
	Desc      string         `gorm:"column:desc;type:varchar(255);comment:权益描述;not null;" json:"desc"`                            // 权益描述
	Types     uint8          `gorm:"column:types;type:tinyint UNSIGNED;comment:权益类型 1-折扣 2-赠品 3-服务 4-优惠卷;not null;" json:"types"` // 权益类型 1-折扣 2-赠品 3-服务 4-优惠卷
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

// 会员权益表
func (mb *MemberBenefit) TableName() string {
	return "member_benefit"
}

// 权益添加
func (mb *MemberBenefit) MemberBenefitAdd() error {
	return inits.DB.Create(&mb).Error
}

// 权益展示
func (mb *MemberBenefit) MemberBenefitFind() (MemberBenefitFind []*MemberBenefit, err error) {
	err = inits.DB.Find(&MemberBenefitFind).Error
	return
}

// 权益详情
func (mb *MemberBenefit) MemberBenefitDetail() error {
	return inits.DB.Where("id = ?", mb.Id).Limit(1).Find(&mb).Error
}

// 权益id查询
func (mb *MemberBenefit) GetMemberBenefitInfoById(id int) error {
	return inits.DB.Where("id = ?", id).Limit(1).Find(&mb).Error
}
